-- @owner: @zym_2025
-- @date: 2025/07/29
-- @testpoint: 通过return语句查询rowcount_big()的值

@connect PrimaryDbDmode;
--step1:创建表t_rowcount0003;expect:成功
drop table if exists t_rowcount0003;
create table t_rowcount0003(id int, name varchar(20));
insert into t_rowcount0003 values(1, 'zhangsan'), (2, 'lisi'), (3, 'wangwu');

--step2:创建自定义函数;expect:成功
drop function if exists func_rowcount0003;
CREATE OR REPLACE FUNCTION func_rowcount0003(table_name TEXT)
RETURNS TABLE(total_rows INT, affected_rows INT)
AS $$
DECLARE
  row_count INT;
  affected_rows INT;
BEGIN
  EXECUTE format('DELETE FROM %I WHERE id > 1', table_name);
  SELECT rowcount_big() INTO affected_rows;
  EXECUTE format('SELECT COUNT(*) FROM %I', table_name) INTO row_count;
  RETURN QUERY SELECT row_count, affected_rows;
END;
$$ LANGUAGE pltsql;
/
--step3:调用自定义函数;expect:row_count为1，affected_rows为2
select * from func_rowcount0003('t_rowcount0003');

--step4:清理环境;expect:成功
drop table if exists t_rowcount0003;
drop function if exists func_rowcount0003;